package com.example.flashsales;

import com.example.flashsales.entity.vo.UserVo;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class Factory {
    private  Map<Long, UserVo> onlineUsers = new HashMap<>();

    private static Factory factory;

    public static synchronized Factory getFactory(){
        if (factory == null){
            synchronized (Factory.class){
                if (factory == null){
                    factory = new Factory();
                }
            }
        }
        return factory;
    }






    public Map<Long, UserVo> getOnlineUsers() {
        return this.onlineUsers;
    }



    public void addUser(UserVo userVo){
        onlineUsers.put(userVo.getId(),userVo);
    }
}
